package com.todo.content.application.convert;

import com.alibaba.fastjson.JSONObject;
import com.google.api.client.util.Lists;
import com.todo.common.common.entity.BaseUserVO;
import com.todo.common.common.entity.response.page.PageResult;
import com.todo.common.common.enums.AllowedCommentEnum;
import com.todo.common.common.enums.BusinessSceneEnum;
import com.todo.common.common.enums.EnableTypeEnum;
import com.todo.common.common.enums.SourceEnum;
import com.todo.common.common.enums.biz.PrivateTypeEnum;
import com.todo.common.utils.StringUtils;
import com.todo.common.utils.TodoCommonUtils;
import com.todo.content.api.base.ContentRelation;
import com.todo.content.api.request.InsertContentDetailRequest;
import com.todo.content.api.request.SavePreCheckRequest;
import com.todo.content.api.request.UpdateContentDetailRequest;
import com.todo.content.api.response.ContentDetailResponse;
import com.todo.content.api.response.ContentInfoResponse;
import com.todo.content.application.entity.bo.*;
import com.todo.content.application.entity.condition.ContentClassifyConditionBO;
import com.todo.content.application.entity.condition.ContentInfoConditionBO;
import com.todo.content.application.entity.condition.ContentTopicConditionBO;
import com.todo.content.application.entity.condition.TopicRelationConditionBO;
import com.todo.content.common.enums.ContentRelationTypeEnum;
import com.todo.content.common.enums.ContentStatusEnum;
import com.todo.content.common.enums.TopicTypeEnum;
import com.todo.content.iface.backend.request.*;
import com.todo.content.iface.backend.response.*;
import com.todo.content.iface.frontend.request.ContentClassifyBaseListParam;
import com.todo.content.iface.frontend.request.InsertContentParam;
import com.todo.content.iface.frontend.request.UpdateContentParam;
import com.todo.content.iface.frontend.response.*;
import com.todo.content.infrastructure.entity.condition.ContentClassifyCondition;
import com.todo.content.infrastructure.entity.condition.ContentInfoCondition;
import com.todo.content.infrastructure.entity.condition.ContentTopicCondition;
import com.todo.content.infrastructure.entity.condition.TopicRelationCondition;
import com.todo.content.infrastructure.entity.domain.ContentDetailDO;
import com.todo.content.infrastructure.entity.po.ContentClassifyPO;
import com.todo.content.infrastructure.entity.po.ContentInfoPO;
import com.todo.content.infrastructure.entity.po.ContentTopicPO;
import com.todo.content.infrastructure.entity.po.ContentTopicRelationPO;
import com.todo.content.infrastructure.helper.es.entity.ContentDetailEntity;
import com.todo.user.api.response.BaseUserInfoResponse;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author azhebuxing
 * @date 2024/7/5 12:17
 * @description
 */
public class ContentConvert {

    public static ContentTopicCondition convertToContentTopicCondition(ContentTopicConditionBO topicConditionBO) {
        if (topicConditionBO == null) {
            return null;
        }
        ContentTopicCondition condition = new ContentTopicCondition();
        condition.setPageIndex(topicConditionBO.getPageIndex());
        condition.setPageSize(topicConditionBO.getPageSize());
        condition.setCurrentIndex(topicConditionBO.getCurrentIndex());
        condition.setName(topicConditionBO.getName());
        condition.setTopicType(topicConditionBO.getTopicType() == null ? null : topicConditionBO.getTopicType().getType());
        condition.setIsEnable(topicConditionBO.getIsEnable() == null ? null : topicConditionBO.getIsEnable().getType());
        condition.setCreateUser(topicConditionBO.getCreateUser());
        return condition;
    }

    public static ContentTopicPO convertToContentTopicPO(ContentTopicBO contentTopicBO) {
        if (contentTopicBO == null) {
            return null;
        }
        ContentTopicPO contentTopicPO = new ContentTopicPO();
        contentTopicPO.setId(contentTopicBO.getTopicId() == null ? TodoCommonUtils.buildLongGuid() : contentTopicBO.getTopicId());
        contentTopicPO.setTopicType(contentTopicBO.getTopicType().getType());
        contentTopicPO.setBackendImg(contentTopicBO.getBackendImg());
        contentTopicPO.setName(contentTopicBO.getName());
        contentTopicPO.setDesc(contentTopicBO.getDesc());
        contentTopicPO.setSeeCount(contentTopicBO.getSeeCount());
        contentTopicPO.setJoinCount(contentTopicBO.getJoinCount());
        contentTopicPO.setIsEnable(contentTopicBO.getIsEnable() == null ? EnableTypeEnum.ENABLE.getType() : contentTopicBO.getIsEnable().getType());
        contentTopicPO.setContentCount(contentTopicBO.getContentCount());
        contentTopicPO.setCreateUser(contentTopicBO.getCreateUser());
        contentTopicPO.setLastUpdateUser(contentTopicBO.getLastUpdateUser());
        contentTopicPO.setIsDelete(0);
        contentTopicPO.setCreateTime(new Date());
        contentTopicPO.setUpdateTime(new Date());
        return contentTopicPO;
    }

    public static TopicRelationCondition convertToContentTopicRelationCondition(TopicRelationConditionBO conditionBO) {
        if (conditionBO == null) {
            return null;
        }
        TopicRelationCondition condition = new TopicRelationCondition();
        condition.setTopicCode(conditionBO.getTopicCode());
        condition.setPageIndex(conditionBO.getPageIndex());
        condition.setPageSize(conditionBO.getPageSize());
        condition.setCurrentIndex(conditionBO.getCurrentIndex());
        return condition;
    }

    public static ContentTopicRelationBO convertToContentTopicRelationBO(ContentTopicRelationPO contentTopicRelationPO) {
        if (contentTopicRelationPO == null) {
            return null;
        }
        ContentTopicRelationBO contentTopicRelationBO = new ContentTopicRelationBO();
        contentTopicRelationBO.setId(contentTopicRelationPO.getId());
        contentTopicRelationBO.setContentId(contentTopicRelationPO.getContentId());
        contentTopicRelationBO.setTopicCode(contentTopicRelationPO.getTopicCode());
        contentTopicRelationBO.setTopicName(contentTopicRelationPO.getTopicName());
        return contentTopicRelationBO;
    }

    public static ContentDetailResp convertToContentDetailResp(ContentDetailBO contentDetailBO) {
        if (contentDetailBO == null || contentDetailBO.getContentInfoBO() == null) {
            return null;
        }
        ContentInfoBO contentInfoBO = contentDetailBO.getContentInfoBO();
        ContentDetailResp contentDetailResp = new ContentDetailResp();
        contentDetailResp.setId(contentInfoBO.getId());
        contentDetailResp.setTitle(contentInfoBO.getTitle());
        contentDetailResp.setContent(contentInfoBO.getContent());
        contentDetailResp.setMainImg(contentInfoBO.getMainImg());
        contentDetailResp.setClassifyCode(contentInfoBO.getClassifyCode());
        contentDetailResp.setStatus(contentInfoBO.getStatus().getType());
        contentDetailResp.setSource(contentInfoBO.getSource());
        contentDetailResp.setLikeCount(contentInfoBO.getLikeCount());
        contentDetailResp.setSeeCount(contentInfoBO.getSeeCount());
        contentDetailResp.setCommentCount(contentInfoBO.getCommentCount());
        contentDetailResp.setAllowComment(contentInfoBO.getAllowComment().getType());
        contentDetailResp.setUserId(contentInfoBO.getUserId());
        if (contentInfoBO.getExtra() != null) {
            contentDetailResp.setImgList(contentInfoBO.getExtra().getRelationImgList());
        }
        return contentDetailResp;
    }

    public static ContentInfoConditionBO convertToContentInfoConditionBO(QueryContentInfoByConditionReq req) {
        if (req == null) {
            return null;
        }
        ContentInfoConditionBO contentInfoConditionBO = new ContentInfoConditionBO();
        contentInfoConditionBO.setCurrentIndex(req.getCurrentIndex());
        contentInfoConditionBO.setPageIndex(req.getPageIndex());
        contentInfoConditionBO.setPageSize(req.getPageSize());
        contentInfoConditionBO.setTitle(req.getTitle());
        contentInfoConditionBO.setClassifyCode(req.getClassifyCode());
        contentInfoConditionBO.setStatus(ContentStatusEnum.getByType(req.getStatus()));
        contentInfoConditionBO.setUserId(req.getUserId());
        return contentInfoConditionBO;
    }

    public static PageResult<ContentBaseInfoResp> convertToPageContentBaseInfoResp(PageResult<ContentInfoBO> pageResult) {
        if (pageResult == null) {
            return null;
        }
        if (CollectionUtils.isEmpty(pageResult.getResults())) {
            return PageResult.of(new ArrayList<>(), pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal());
        }
        PageResult<ContentBaseInfoResp> result = new PageResult<>();
        result.setPageCount(pageResult.getPageCount());
        result.setCurrentIndex(pageResult.getCurrentIndex());
        result.setHasNext(pageResult.isHasNext());
        result.setPageNum(pageResult.getPageNum());
        result.setPageSize(pageResult.getPageSize());
        result.setTotal(pageResult.getTotal());
        result.setResults(pageResult.getResults().stream().map(ContentConvert::convertToContentBaseInfoResp).collect(Collectors.toList()));
        return result;
    }

    public static ContentClassifyBO convertToContentClassifyBO(ContentClassifyPO contentClassifyPO) {
        if (contentClassifyPO == null) {
            return null;
        }
        ContentClassifyBO contentClassifyBO = new ContentClassifyBO();
        contentClassifyBO.setClassifyId(contentClassifyPO.getId());
        contentClassifyBO.setBusinessScene(BusinessSceneEnum.getBusinessSceneEnumByScene(contentClassifyPO.getBusinessScene()));
        contentClassifyBO.setCode(contentClassifyPO.getCode());
        contentClassifyBO.setCreateUser(contentClassifyPO.getCreateUser());
        contentClassifyBO.setDesc(contentClassifyPO.getDesc());
        contentClassifyBO.setExtra(JSONObject.parseObject(contentClassifyPO.getExtra(), ContentClassifyBO.Extra.class));
        contentClassifyBO.setIsEnable(EnableTypeEnum.getByType(contentClassifyPO.getIsEnable()));
        contentClassifyBO.setLastUpdateUser(contentClassifyPO.getLastUpdateUser());
        contentClassifyBO.setMainImg(contentClassifyPO.getMainImg());
        contentClassifyBO.setName(contentClassifyPO.getName());
        return contentClassifyBO;
    }

    public static ContentDetailDO convertToContentDetailDO(ContentDetailBO contentDetailBO) {
        if (contentDetailBO == null || contentDetailBO.getContentInfoBO() == null) {
            return null;
        }
        ContentInfoBO contentInfoBO = contentDetailBO.getContentInfoBO();
        ContentDetailDO contentDetailDO = new ContentDetailDO();
        contentDetailDO.setId(contentInfoBO.getId() == null ? TodoCommonUtils.buildLongGuid() : contentInfoBO.getId());
        contentDetailDO.setUserId(contentInfoBO.getUserId());
        ContentDetailDO.ContentInfo contentInfo = new ContentDetailDO.ContentInfo();
        contentInfo.setMainImg(contentInfoBO.getMainImg());
        contentInfo.setClassifyCode(contentInfoBO.getClassifyCode());
        contentInfo.setContent(contentInfoBO.getContent());
        contentInfo.setExtra(JSONObject.toJSONString(contentInfoBO.getExtra()));
        contentInfo.setStatus(contentInfoBO.getStatus().getType());
        contentInfo.setSource(contentInfoBO.getSource());
        contentInfo.setTitle(contentInfoBO.getTitle());
        contentInfo.setAllowComment(contentInfoBO.getAllowComment().getType());
        contentInfo.setSeeCount(contentInfoBO.getSeeCount());
        contentInfo.setCommentCount(contentInfoBO.getCommentCount());
        contentInfo.setCollectCount(contentInfoBO.getCollectCount());
        contentInfo.setLikeCount(contentInfoBO.getLikeCount());
        contentInfo.setIsPrivate(contentInfoBO.getIsPrivate().getType());
        contentDetailDO.setContentInfo(contentInfo);

        if (CollectionUtils.isNotEmpty(contentDetailBO.getContentRelationBOList())) {
            List<ContentDetailDO.ContentRelation> contentRelationList = new ArrayList<>();
            contentDetailBO.getContentRelationBOList().forEach(contentRelationBO -> {
                ContentDetailDO.ContentRelation contentRelation = new ContentDetailDO.ContentRelation();
                contentRelation.setJumpUrl(contentRelationBO.getJumpUrl());
                contentRelation.setRelationId(contentRelationBO.getRelationId());
                contentRelation.setRelationName(contentRelationBO.getRelationName());
                contentRelation.setRelationImg(contentRelationBO.getRelationImg());
                contentRelation.setRelationType(contentRelationBO.getRelationType().getType());
                contentRelation.setSort(contentRelationBO.getSort());
                contentRelation.setIsOutside(contentRelationBO.getIsOutside());
                contentRelationList.add(contentRelation);
            });
            contentDetailDO.setContentRelationList(contentRelationList);
        }

        return contentDetailDO;
    }

    public static ContentBaseInfoResp convertToContentBaseInfoResp(ContentInfoBO contentInfoBO) {
        if (contentInfoBO == null) {
            return null;
        }
        ContentBaseInfoResp contentBaseInfoResp = new ContentBaseInfoResp();
        contentBaseInfoResp.setId(contentInfoBO.getId());
        contentBaseInfoResp.setTitle(contentInfoBO.getTitle());
        contentBaseInfoResp.setMainImg(contentInfoBO.getMainImg());
        contentBaseInfoResp.setClassifyCode(contentInfoBO.getClassifyCode());
        contentBaseInfoResp.setStatus(contentInfoBO.getStatus().getType());
        contentBaseInfoResp.setSource(contentInfoBO.getSource());
        contentBaseInfoResp.setLikeCount(contentInfoBO.getLikeCount());
        contentBaseInfoResp.setCommentCount(contentInfoBO.getCommentCount());
        contentBaseInfoResp.setSeeCount(contentInfoBO.getSeeCount());
        contentBaseInfoResp.setAllowComment(contentInfoBO.getAllowComment().getType());
        contentBaseInfoResp.setUserId(contentInfoBO.getUserId());
        return contentBaseInfoResp;
    }

    public static ContentClassifyBO convertToContentClassifyBO(InsertContentClassifyReq req) {
        if (req == null) {
            return null;
        }
        ContentClassifyBO contentClassifyBO = new ContentClassifyBO();
        contentClassifyBO.setClassifyId(TodoCommonUtils.buildLongGuid());
        contentClassifyBO.setCode(req.getCode());
        contentClassifyBO.setDesc(req.getDesc());
        contentClassifyBO.setName(req.getName());
        contentClassifyBO.setBusinessScene(BusinessSceneEnum.getBusinessSceneEnumByScene(req.getBusinessScene()));
        contentClassifyBO.setMainImg(req.getMainImg());
        contentClassifyBO.setIsEnable(EnableTypeEnum.getByType(req.getIsEnable()));
        contentClassifyBO.setCreateUser(String.valueOf(req.get_staff().getUsername()));
        contentClassifyBO.setLastUpdateUser(String.valueOf(req.get_staff().getUsername()));
        return contentClassifyBO;
    }

    public static ContentClassifyBO convertToContentClassifyBO(UpdateContentClassifyByIdReq req) {
        if (req == null) {
            return null;
        }
        ContentClassifyBO contentClassifyBO = new ContentClassifyBO();
        contentClassifyBO.setClassifyId(req.getId());
        contentClassifyBO.setCode(req.getCode());
        contentClassifyBO.setDesc(req.getDesc());
        contentClassifyBO.setName(req.getName());
        contentClassifyBO.setBusinessScene(BusinessSceneEnum.getBusinessSceneEnumByScene(req.getBusinessScene()));
        contentClassifyBO.setMainImg(req.getMainImg());
        contentClassifyBO.setIsEnable(EnableTypeEnum.getByType(req.getIsEnable()));
        contentClassifyBO.setLastUpdateUser(String.valueOf(req.get_staff().getUserId()));
        return contentClassifyBO;
    }


    public static ContentClassifyDetailByIdResp convertToContentClassifyDetailByIdResp(ContentClassifyBO contentClassifyBO) {
        if (contentClassifyBO == null) {
            return null;
        }
        ContentClassifyDetailByIdResp contentClassifyDetailByIdResp = new ContentClassifyDetailByIdResp();
        contentClassifyDetailByIdResp.setCode(contentClassifyBO.getCode());
        contentClassifyDetailByIdResp.setDesc(contentClassifyBO.getDesc());
        contentClassifyDetailByIdResp.setId(contentClassifyBO.getClassifyId());
        contentClassifyDetailByIdResp.setMainImg(contentClassifyBO.getMainImg());
        contentClassifyDetailByIdResp.setName(contentClassifyBO.getName());
        contentClassifyDetailByIdResp.setBusinessScene(contentClassifyBO.getBusinessScene().getScene());
        contentClassifyDetailByIdResp.setIsEnable(contentClassifyBO.getIsEnable().getType());
        contentClassifyDetailByIdResp.setCreateUser(contentClassifyBO.getCreateUser());
        return contentClassifyDetailByIdResp;
    }

    public static ContentClassifyConditionBO convertToContentClassifyConditionBO(QueryContentClassifyByConditionReq req) {
        if (req == null) {
            return null;
        }
        ContentClassifyConditionBO contentClassifyConditionBO = new ContentClassifyConditionBO();
        contentClassifyConditionBO.setCurrentIndex(req.getCurrentIndex());
        contentClassifyConditionBO.setPageIndex(req.getPageIndex());
        contentClassifyConditionBO.setPageSize(req.getPageSize());
        contentClassifyConditionBO.setName(req.getName());
        contentClassifyConditionBO.setCode(req.getCode());
        contentClassifyConditionBO.setBusinessScene(BusinessSceneEnum.getBusinessSceneEnumByScene(req.getBusinessScene()));
        contentClassifyConditionBO.setIsEnable(EnableTypeEnum.getByType(req.getIsEnable()));
        contentClassifyConditionBO.setCreateUser(req.getCreateUser());
        return contentClassifyConditionBO;
    }

    public static ContentClassifyConditionBO convertToContentClassifyConditionBO(ContentClassifyBaseListParam param) {
        if (param == null) {
            return null;
        }
        ContentClassifyConditionBO contentClassifyConditionBO = new ContentClassifyConditionBO();
        contentClassifyConditionBO.setCurrentIndex(param.getCurrentIndex());
        contentClassifyConditionBO.setPageIndex(param.getPageIndex());
        contentClassifyConditionBO.setPageSize(param.getPageSize());
        return contentClassifyConditionBO;
    }

    public static PageResult<QueryContentClassifyByConditionResp> convertToQueryContentClassifyByConditionRespPage(PageResult<ContentClassifyBO> pageResult) {
        if (pageResult == null) {
            return null;
        }
        if (CollectionUtils.isEmpty(pageResult.getResults())) {
            return PageResult.of(new ArrayList<>(), pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal());
        }
        PageResult<QueryContentClassifyByConditionResp> result = new PageResult<>();
        result.setPageCount(pageResult.getPageCount());
        result.setCurrentIndex(pageResult.getCurrentIndex());
        result.setHasNext(pageResult.isHasNext());
        result.setPageNum(pageResult.getPageNum());
        result.setPageSize(pageResult.getPageSize());
        result.setTotal(pageResult.getTotal());
        result.setResults(pageResult.getResults().stream().map(ContentConvert::convertToQueryContentClassifyByConditionResp).collect(Collectors.toList()));
        return result;
    }

    public static QueryContentClassifyByConditionResp convertToQueryContentClassifyByConditionResp(ContentClassifyBO contentClassifyBO) {
        if (contentClassifyBO == null) {
            return null;
        }
        QueryContentClassifyByConditionResp queryContentClassifyByConditionResp = new QueryContentClassifyByConditionResp();
        queryContentClassifyByConditionResp.setCode(contentClassifyBO.getCode());
        queryContentClassifyByConditionResp.setId(contentClassifyBO.getClassifyId());
        queryContentClassifyByConditionResp.setMainImg(contentClassifyBO.getMainImg());
        queryContentClassifyByConditionResp.setName(contentClassifyBO.getName());
        queryContentClassifyByConditionResp.setBusinessScene(contentClassifyBO.getBusinessScene().getScene());
        queryContentClassifyByConditionResp.setIsEnable(contentClassifyBO.getIsEnable().getType());
        queryContentClassifyByConditionResp.setCreateUser(contentClassifyBO.getCreateUser());
        return queryContentClassifyByConditionResp;
    }

    public static ContentTopicBO convertToContentTopicBO(ContentTopicPO contentTopicPO) {
        if (contentTopicPO == null) {
            return null;
        }
        ContentTopicBO contentTopicBO = new ContentTopicBO();
        contentTopicBO.setTopicId(contentTopicPO.getId());
        contentTopicBO.setTopicType(TopicTypeEnum.getByType(contentTopicPO.getTopicType()));
        contentTopicBO.setBackendImg(contentTopicPO.getBackendImg());
        contentTopicBO.setName(contentTopicPO.getName());
        contentTopicBO.setDesc(contentTopicPO.getDesc());
        contentTopicBO.setSeeCount(contentTopicPO.getSeeCount());
        contentTopicBO.setJoinCount(contentTopicPO.getJoinCount());
        contentTopicBO.setIsEnable(EnableTypeEnum.getByType(contentTopicPO.getIsEnable()));
        contentTopicBO.setContentCount(contentTopicPO.getContentCount());
        contentTopicBO.setCreateUser(contentTopicPO.getCreateUser());
        contentTopicBO.setLastUpdateUser(contentTopicPO.getLastUpdateUser());
        return contentTopicBO;
    }

    public static ContentTopicBO convertToContentTopicBO(InsertContentTopicReq req) {
        if (req == null) {
            return null;
        }
        ContentTopicBO contentTopicBO = new ContentTopicBO();
        contentTopicBO.setTopicId(TodoCommonUtils.buildLongGuid());
        contentTopicBO.setName(req.getName());
        contentTopicBO.setDesc(req.getDesc());
        contentTopicBO.setTopicType(TopicTypeEnum.getByType(req.getTopicType()));
        contentTopicBO.setIsEnable(EnableTypeEnum.getByType(req.getIsEnable()));
        contentTopicBO.setCreateUser(req.get_staff().getUsername());
        contentTopicBO.setLastUpdateUser(req.get_staff().getUsername());
        contentTopicBO.setContentCount(0);
        contentTopicBO.setJoinCount(0);
        contentTopicBO.setSeeCount(0);
        contentTopicBO.setBackendImg(req.getBackendImg());
        return contentTopicBO;
    }

    public static ContentTopicBO convertToContentTopicBO(UpdateContentTopicByIdReq req) {
        if (req == null) {
            return null;
        }
        ContentTopicBO contentTopicBO = new ContentTopicBO();
        contentTopicBO.setTopicId(req.getId());
        contentTopicBO.setName(req.getName());
        contentTopicBO.setDesc(req.getDesc());
        contentTopicBO.setTopicType(TopicTypeEnum.getByType(req.getTopicType()));
        contentTopicBO.setIsEnable(EnableTypeEnum.getByType(req.getIsEnable()));
        contentTopicBO.setLastUpdateUser(req.get_staff().getUsername());
        contentTopicBO.setBackendImg(req.getBackendImg());
        return contentTopicBO;
    }

    public static ContentTopicDetailByIdResp convertToContentTopicDetailByIdResp(ContentTopicBO contentTopicBO) {
        if (contentTopicBO == null) {
            return null;
        }
        ContentTopicDetailByIdResp contentTopicDetailByIdResp = new ContentTopicDetailByIdResp();
        contentTopicDetailByIdResp.setBackendImg(contentTopicBO.getBackendImg());
        contentTopicDetailByIdResp.setDesc(contentTopicBO.getDesc());
        contentTopicDetailByIdResp.setId(contentTopicBO.getTopicId());
        contentTopicDetailByIdResp.setJoinCount(contentTopicBO.getJoinCount());
        contentTopicDetailByIdResp.setName(contentTopicBO.getName());
        contentTopicDetailByIdResp.setSeeCount(contentTopicBO.getSeeCount());
        contentTopicDetailByIdResp.setIsEnable(contentTopicBO.getIsEnable().getType());
        contentTopicDetailByIdResp.setTopicType(contentTopicBO.getTopicType().getType());
        contentTopicDetailByIdResp.setContentCount(contentTopicBO.getContentCount());
        contentTopicDetailByIdResp.setCreateUser(contentTopicBO.getCreateUser());
        contentTopicDetailByIdResp.setLastUpdateUser(contentTopicBO.getLastUpdateUser());
        return contentTopicDetailByIdResp;
    }

    public static ContentTopicConditionBO convertToContentTopicConditionBO(QueryContentTopicByConditionReq req) {
        if (req == null) {
            return null;
        }
        ContentTopicConditionBO contentTopicConditionBO = new ContentTopicConditionBO();
        contentTopicConditionBO.setCurrentIndex(req.getCurrentIndex());
        contentTopicConditionBO.setPageIndex(req.getPageIndex());
        contentTopicConditionBO.setPageSize(req.getPageSize());
        contentTopicConditionBO.setName(req.getName());
        contentTopicConditionBO.setTopicType(TopicTypeEnum.getByType(req.getTopicType()));
        contentTopicConditionBO.setIsEnable(EnableTypeEnum.getByType(req.getIsEnable()));
        contentTopicConditionBO.setCreateUser(req.getCreateUser());
        return contentTopicConditionBO;
    }

    public static PageResult<QueryContentTopicByConditionResp> convertToPageQueryContentTopicByConditionResp(PageResult<ContentTopicBO> pageResult) {
        if (pageResult == null) {
            return null;
        }
        if (CollectionUtils.isEmpty(pageResult.getResults())) {
            return PageResult.of(new ArrayList<>(), pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal());
        }
        PageResult<QueryContentTopicByConditionResp> result = new PageResult<>();
        result.setPageCount(pageResult.getPageCount());
        result.setCurrentIndex(pageResult.getCurrentIndex());
        result.setHasNext(pageResult.isHasNext());
        result.setPageNum(pageResult.getPageNum());
        result.setPageSize(pageResult.getPageSize());
        result.setTotal(pageResult.getTotal());
        result.setResults(pageResult.getResults().stream().map(ContentConvert::convertToQueryContentTopicByConditionResp).collect(Collectors.toList()));
        return result;
    }

    private static QueryContentTopicByConditionResp convertToQueryContentTopicByConditionResp(ContentTopicBO contentTopicBO) {
        if (contentTopicBO == null) {
            return null;
        }
        QueryContentTopicByConditionResp queryContentTopicByConditionResp = new QueryContentTopicByConditionResp();
        queryContentTopicByConditionResp.setBackendImg(contentTopicBO.getBackendImg());
        queryContentTopicByConditionResp.setId(contentTopicBO.getTopicId());
        queryContentTopicByConditionResp.setJoinCount(contentTopicBO.getJoinCount());
        queryContentTopicByConditionResp.setName(contentTopicBO.getName());
        queryContentTopicByConditionResp.setSeeCount(contentTopicBO.getSeeCount());
        queryContentTopicByConditionResp.setIsEnable(contentTopicBO.getIsEnable().getType());
        queryContentTopicByConditionResp.setTopicType(contentTopicBO.getTopicType().getType());
        queryContentTopicByConditionResp.setContentCount(contentTopicBO.getContentCount());
        queryContentTopicByConditionResp.setCreateUser(contentTopicBO.getCreateUser());
        return queryContentTopicByConditionResp;
    }

    public static ContentClassifyPO convertToContentClassifyPO(ContentClassifyBO contentClassifyBO) {
        if (contentClassifyBO == null) {
            return null;
        }
        ContentClassifyPO contentClassifyPO = new ContentClassifyPO();
        contentClassifyPO.setId(contentClassifyBO.getClassifyId() == null ? TodoCommonUtils.buildLongGuid() : contentClassifyBO.getClassifyId());
        contentClassifyPO.setBusinessScene(contentClassifyBO.getBusinessScene().getScene());
        contentClassifyPO.setCode(contentClassifyBO.getCode());
        contentClassifyPO.setCreateUser(contentClassifyBO.getCreateUser());
        contentClassifyPO.setDesc(contentClassifyBO.getDesc());
        contentClassifyPO.setExtra(JSONObject.toJSONString(contentClassifyBO.getExtra()));
        contentClassifyPO.setIsEnable(contentClassifyBO.getIsEnable().getType());
        contentClassifyPO.setLastUpdateUser(contentClassifyBO.getLastUpdateUser());
        contentClassifyPO.setMainImg(contentClassifyBO.getMainImg());
        contentClassifyPO.setName(contentClassifyBO.getName());
        contentClassifyPO.setIsDelete(0);
        contentClassifyPO.setCreateTime(new Date());
        contentClassifyPO.setUpdateTime(new Date());
        return contentClassifyPO;
    }

    public static ContentClassifyCondition convertToContentClassifyCondition(ContentClassifyConditionBO conditionBO) {
        if (conditionBO == null) {
            return null;
        }
        ContentClassifyCondition condition = new ContentClassifyCondition();
        condition.setPageIndex(conditionBO.getPageIndex());
        condition.setPageSize(conditionBO.getPageSize());
        condition.setCurrentIndex(conditionBO.getCurrentIndex());
        condition.setName(conditionBO.getName());
        condition.setCode(conditionBO.getCode());
        condition.setBusinessScene(conditionBO.getBusinessScene() == null ? null : conditionBO.getBusinessScene().getScene());
        condition.setCreateUser(conditionBO.getCreateUser());
        return condition;
    }

    public static ContentDetailBO convertToContentDetailBO(ContentDetailDO contentDetailDO) {
        if (contentDetailDO == null || contentDetailDO.getContentInfo() == null) {
            return null;
        }
        ContentDetailBO contentDetailBO = new ContentDetailBO();
        ContentDetailDO.ContentInfo contentInfo = contentDetailDO.getContentInfo();
        ContentInfoBO contentInfoBO = new ContentInfoBO();
        contentInfoBO.setUserId(contentDetailDO.getUserId());
        contentInfoBO.setAllowComment(AllowedCommentEnum.getByType(contentInfo.getAllowComment()));
        contentInfoBO.setClassifyCode(contentInfo.getClassifyCode());
        contentInfoBO.setContent(contentInfo.getContent());
        contentInfoBO.setExtra(JSONObject.parseObject(contentInfo.getExtra(), ContentInfoBO.Extra.class));
        contentInfoBO.setId(contentDetailDO.getId());
        contentInfoBO.setIsPrivate(PrivateTypeEnum.getByType(contentInfo.getIsPrivate()));
        contentInfoBO.setLikeCount(contentInfo.getLikeCount());
        contentInfoBO.setMainImg(contentInfo.getMainImg());
        contentInfoBO.setSeeCount(contentInfo.getSeeCount());
        contentInfoBO.setCommentCount(contentInfo.getCommentCount());
        contentInfoBO.setCollectCount(contentInfo.getCollectCount());
        contentInfoBO.setSource(contentInfo.getSource());
        contentInfoBO.setStatus(ContentStatusEnum.getByType(contentInfo.getStatus()));
        contentInfoBO.setTitle(contentInfo.getTitle());
        contentInfoBO.setUserId(contentDetailDO.getUserId());
        if (StringUtils.isNotBlank(contentInfo.getExtra())) {
            contentInfoBO.setExtra(JSONObject.parseObject(contentInfo.getExtra(), ContentInfoBO.Extra.class));
        }
        contentDetailBO.setContentInfoBO(contentInfoBO);
        if (CollectionUtils.isNotEmpty(contentDetailDO.getContentRelationList())) {
            List<ContentRelationBO> contentRelationBOList = new ArrayList<>();
            contentDetailDO.getContentRelationList().forEach(contentRelationDO -> {
                ContentRelationBO contentRelationBO = new ContentRelationBO();
                contentRelationBO.setJumpUrl(contentRelationDO.getJumpUrl());
                contentRelationBO.setRelationId(contentRelationDO.getRelationId());
                contentRelationBO.setRelationImg(contentRelationDO.getRelationImg());
                contentRelationBO.setRelationName(contentRelationDO.getRelationName());
                contentRelationBO.setRelationType(ContentRelationTypeEnum.getByType(contentRelationDO.getRelationType()));
                contentRelationBO.setSort(contentRelationDO.getSort());
                contentRelationBO.setIsOutside(contentRelationDO.getIsOutside());
                contentRelationBOList.add(contentRelationBO);
            });
            contentDetailBO.setContentRelationBOList(contentRelationBOList);
        }
        return contentDetailBO;
    }

    public static ContentDetailBO convertToContentDetailBO(InsertContentDetailRequest request) {
        if (request == null) {
            return null;
        }
        ContentDetailBO contentDetailBO = new ContentDetailBO();
        ContentInfoBO contentInfoBO = new ContentInfoBO();
        contentInfoBO.setUserId(request.getUserId());
        contentInfoBO.setAllowComment(request.getAllowComment());
        contentInfoBO.setClassifyCode(request.getClassifyCode());
        contentInfoBO.setContent(request.getContent());
        ContentInfoBO.Extra extra = new ContentInfoBO.Extra();
        extra.setRelationImgList(request.getRelationImgList());
        contentInfoBO.setExtra(extra);
        contentInfoBO.setIsPrivate(request.getIsPrivate());
        contentInfoBO.setLikeCount(0);
        contentInfoBO.setMainImg(request.getMainImg());
        contentInfoBO.setSeeCount(0);
        contentInfoBO.setCommentCount(0);
        contentInfoBO.setCollectCount(0);
        contentInfoBO.setSource(SourceEnum.PLATFORM.getType());
        contentInfoBO.setTitle(request.getTitle());
        contentDetailBO.setContentInfoBO(contentInfoBO);
        if (CollectionUtils.isNotEmpty(request.getContentRelationList())) {
            List<ContentRelationBO> contentRelationBOList = new ArrayList<>();
            request.getContentRelationList().forEach(contentRelationDO -> {
                ContentRelationBO contentRelationBO = new ContentRelationBO();
                contentRelationBO.setJumpUrl(contentRelationDO.getJumpUrl());
                contentRelationBO.setRelationId(contentRelationDO.getRelationId());
                contentRelationBO.setRelationType(contentRelationDO.getRelationType());
                contentRelationBO.setSort(contentRelationDO.getSort());
                contentRelationBOList.add(contentRelationBO);
            });
            contentDetailBO.setContentRelationBOList(contentRelationBOList);
        }
        return contentDetailBO;
    }

    public static ContentDetailBO convertToContentDetailBO(SavePreCheckRequest request) {
        if (request == null) {
            return null;
        }
        ContentDetailBO contentDetailBO = new ContentDetailBO();
        ContentInfoBO contentInfoBO = new ContentInfoBO();
        contentInfoBO.setUserId(request.getUserId());
        contentInfoBO.setAllowComment(request.getAllowComment());
        contentInfoBO.setClassifyCode(request.getClassifyCode());
        contentInfoBO.setContent(request.getContent());
        ContentInfoBO.Extra extra = new ContentInfoBO.Extra();
        extra.setRelationImgList(request.getRelationImgList());
        contentInfoBO.setExtra(extra);
        contentInfoBO.setIsPrivate(request.getIsPrivate());
        contentInfoBO.setLikeCount(0);
        contentInfoBO.setMainImg(request.getMainImg());
        contentInfoBO.setSeeCount(0);
        contentInfoBO.setCommentCount(0);
        contentInfoBO.setCollectCount(0);
        contentInfoBO.setSource(SourceEnum.PLATFORM.getType());
        contentInfoBO.setStatus(ContentStatusEnum.POSTED);
        contentInfoBO.setTitle(request.getTitle());
        contentDetailBO.setContentInfoBO(contentInfoBO);
        if (CollectionUtils.isNotEmpty(request.getContentRelationList())) {
            List<ContentRelationBO> contentRelationBOList = new ArrayList<>();
            request.getContentRelationList().forEach(contentRelationDO -> {
                ContentRelationBO contentRelationBO = new ContentRelationBO();
                contentRelationBO.setJumpUrl(contentRelationDO.getJumpUrl());
                contentRelationBO.setRelationId(contentRelationDO.getRelationId());
                contentRelationBO.setRelationType(contentRelationDO.getRelationType());
                contentRelationBO.setSort(contentRelationDO.getSort());
                contentRelationBOList.add(contentRelationBO);
            });
            contentDetailBO.setContentRelationBOList(contentRelationBOList);
        }
        return contentDetailBO;
    }

    public static ContentDetailBO convertToContentDetailBO(UpdateContentDetailRequest request) {
        if (request == null) {
            return null;
        }
        ContentDetailBO contentDetailBO = new ContentDetailBO();
        ContentInfoBO contentInfoBO = new ContentInfoBO();
        contentInfoBO.setId(request.getContentId());
        contentInfoBO.setUserId(request.getUserId());
        contentInfoBO.setAllowComment(request.getAllowComment());
        contentInfoBO.setClassifyCode(request.getClassifyCode());
        contentInfoBO.setContent(request.getContent());
        ContentInfoBO.Extra extra = new ContentInfoBO.Extra();
        extra.setRelationImgList(request.getRelationImgList());
        contentInfoBO.setExtra(extra);
        contentInfoBO.setIsPrivate(request.getIsPrivate());
        contentInfoBO.setLikeCount(0);
        contentInfoBO.setMainImg(request.getMainImg());
        contentInfoBO.setSeeCount(0);
        contentInfoBO.setCommentCount(0);
        contentInfoBO.setCollectCount(0);
        contentInfoBO.setSource(SourceEnum.PLATFORM.getType());
        contentInfoBO.setStatus(ContentStatusEnum.POSTED);
        contentInfoBO.setTitle(request.getTitle());
        contentDetailBO.setContentInfoBO(contentInfoBO);
        if (CollectionUtils.isNotEmpty(request.getContentRelationList())) {
            List<ContentRelationBO> contentRelationBOList = new ArrayList<>();
            request.getContentRelationList().forEach(contentRelationDO -> {
                ContentRelationBO contentRelationBO = new ContentRelationBO();
                contentRelationBO.setJumpUrl(contentRelationDO.getJumpUrl());
                contentRelationBO.setRelationId(contentRelationDO.getRelationId());
                contentRelationBO.setRelationType(contentRelationDO.getRelationType());
                contentRelationBO.setSort(contentRelationDO.getSort());
                contentRelationBOList.add(contentRelationBO);
            });
            contentDetailBO.setContentRelationBOList(contentRelationBOList);
        }
        return contentDetailBO;
    }

    public static ContentInfoCondition convertToContentInfoCondition(ContentInfoConditionBO conditionBO) {
        if (conditionBO == null) {
            return null;
        }
        ContentInfoCondition condition = new ContentInfoCondition();
        condition.setClassifyCode(conditionBO.getClassifyCode());
        condition.setPageIndex(conditionBO.getPageIndex());
        condition.setPageSize(conditionBO.getPageSize());
        condition.setStatus(conditionBO.getStatus() == null ? null : conditionBO.getStatus().getType());
        condition.setTitle(conditionBO.getTitle());
        condition.setUserId(conditionBO.getUserId());
        condition.setCurrentIndex(conditionBO.getCurrentIndex());
        return condition;
    }

    public static ContentInfoBO convertToContentInfoBO(ContentInfoPO contentInfoPO) {
        if (contentInfoPO == null) {
            return null;
        }
        ContentInfoBO contentInfoBO = new ContentInfoBO();
        contentInfoBO.setAllowComment(AllowedCommentEnum.getByType(contentInfoPO.getAllowComment()));
        contentInfoBO.setClassifyCode(contentInfoPO.getClassifyCode());
        contentInfoBO.setContent(contentInfoPO.getContent());
        contentInfoBO.setExtra(JSONObject.parseObject(contentInfoPO.getExtra(), ContentInfoBO.Extra.class));
        contentInfoBO.setId(contentInfoPO.getId());
        contentInfoBO.setIsPrivate(PrivateTypeEnum.getByType(contentInfoPO.getIsPrivate()));
        contentInfoBO.setLikeCount(contentInfoPO.getLikeCount());
        contentInfoBO.setMainImg(contentInfoPO.getMainImg());
        contentInfoBO.setSeeCount(contentInfoPO.getSeeCount());
        contentInfoBO.setSource(contentInfoPO.getSource());
        contentInfoBO.setStatus(ContentStatusEnum.getByType(contentInfoPO.getStatus()));
        contentInfoBO.setTitle(contentInfoPO.getTitle());
        contentInfoBO.setUserId(contentInfoPO.getUserId());
        contentInfoBO.setCommentCount(contentInfoPO.getCommentCount());
        contentInfoBO.setCollectCount(contentInfoPO.getCollectCount());
        contentInfoBO.setIsDelete(contentInfoPO.getIsDelete());
        contentInfoBO.setCreateTime(contentInfoPO.getCreateTime());
        contentInfoBO.setUpdateTime(contentInfoPO.getUpdateTime());
        return contentInfoBO;
    }

    public static ContentTopicRelationPO convertToContentTopicRelationPO(ContentTopicRelationBO contentTopicRelationBO) {
        if (contentTopicRelationBO == null) {
            return null;
        }
        ContentTopicRelationPO contentTopicRelationPO = new ContentTopicRelationPO();
        contentTopicRelationPO.setId(contentTopicRelationBO.getId());
        contentTopicRelationPO.setContentId(contentTopicRelationBO.getContentId());
        contentTopicRelationPO.setTopicCode(contentTopicRelationBO.getTopicCode());
        contentTopicRelationPO.setTopicName(contentTopicRelationBO.getTopicName());
        return contentTopicRelationPO;
    }

    public static ContentDetailEntity convertToContentDetailEntity(ContentDetailDO contentDetailDO) {
        if (contentDetailDO == null || contentDetailDO.getContentInfo() == null) {
            return null;
        }
        ContentDetailDO.ContentInfo contentInfo = contentDetailDO.getContentInfo();
        ContentDetailEntity contentDetailEntity = new ContentDetailEntity();
        contentDetailEntity.setMysqlId(contentDetailDO.getId());
        contentDetailEntity.setUserId(contentDetailDO.getUserId());
        contentDetailEntity.setContent(contentInfo.getContent());
        contentDetailEntity.setClassifyCode(contentInfo.getClassifyCode());
        contentDetailEntity.setTitle(contentInfo.getTitle());
        contentDetailEntity.setStatus(contentInfo.getStatus());
        contentDetailEntity.setIsPrivate(contentInfo.getIsPrivate());
        contentDetailEntity.setAllowComment(contentInfo.getAllowComment());
        contentDetailEntity.setMainImg(contentInfo.getMainImg());
        contentDetailEntity.setSeeCount(contentInfo.getSeeCount());
        contentDetailEntity.setLikeCount(contentInfo.getLikeCount());
        contentDetailEntity.setCommentCount(contentInfo.getCommentCount());
        contentDetailEntity.setCollectCount(contentInfo.getCollectCount());
        return contentDetailEntity;
    }


    public static ContentInfoResponse convertToContentInfoResponse(ContentInfoBO contentInfoBO) {
        if (contentInfoBO == null) {
            return null;
        }
        ContentInfoResponse contentInfoResponse = new ContentInfoResponse();
        contentInfoResponse.setContentId(contentInfoBO.getId());
        contentInfoResponse.setUserId(contentInfoBO.getUserId());
        contentInfoResponse.setTitle(contentInfoBO.getTitle());
        contentInfoResponse.setContent(contentInfoBO.getContent());
        contentInfoResponse.setMainImg(contentInfoBO.getMainImg());
        contentInfoResponse.setClassifyCode(contentInfoBO.getClassifyCode());
        contentInfoResponse.setStatus(contentInfoBO.getStatus());
        if (contentInfoBO.getExtra() != null) {
            contentInfoResponse.setRelationImgList(contentInfoBO.getExtra().getRelationImgList());
        }
        contentInfoResponse.setIsPrivate(contentInfoBO.getIsPrivate());
        contentInfoResponse.setAllowComment(contentInfoBO.getAllowComment());
        contentInfoResponse.setSource(SourceEnum.getByType(contentInfoBO.getSource()));
        contentInfoResponse.setSeeCount(contentInfoBO.getSeeCount());
        contentInfoResponse.setLikeCount(contentInfoBO.getLikeCount());
        contentInfoResponse.setCommentCount(contentInfoBO.getCommentCount());
        contentInfoResponse.setCollectCount(contentInfoBO.getCollectCount());
        return contentInfoResponse;
    }

    public static List<ContentTopicBaseVO> convertToContentTopicBaseVOList(List<ContentTopicBO> contentTopicBOList) {
        if (CollectionUtils.isEmpty(contentTopicBOList)) {
            return Lists.newArrayList();
        }
        return contentTopicBOList.stream().map(ContentConvert::convertToContentTopicBaseVO).collect(Collectors.toList());
    }

    public static ContentTopicBaseVO convertToContentTopicBaseVO(ContentTopicBO contentTopicBO) {
        if (contentTopicBO == null) {
            return null;
        }
        ContentTopicBaseVO contentTopicBaseVO = new ContentTopicBaseVO();
        contentTopicBaseVO.setTopicId(contentTopicBO.getTopicId());
        contentTopicBaseVO.setTopicType(contentTopicBO.getTopicType() == null ? null : contentTopicBO.getTopicType().getType());
        contentTopicBaseVO.setName(contentTopicBO.getName());
        contentTopicBaseVO.setTopicTypeStr(contentTopicBO.getTopicType() == null ? null : contentTopicBO.getTopicType().getName());
        contentTopicBaseVO.setBackendImg(contentTopicBO.getBackendImg());
        contentTopicBaseVO.setSeeCount(contentTopicBO.getSeeCount());
        contentTopicBaseVO.setJoinCount(contentTopicBO.getJoinCount());
        contentTopicBaseVO.setContentCount(contentTopicBO.getContentCount());
        contentTopicBaseVO.setIsEnable(contentTopicBO.getIsEnable() == null ? null : contentTopicBO.getIsEnable().getType());
        return contentTopicBaseVO;
    }


    public static ContentTopicDetailVO convertToContentTopicDetailVO(ContentTopicBO contentTopicBO) {
        if (contentTopicBO == null) {
            return null;
        }
        ContentTopicDetailVO contentTopicDetailVO = new ContentTopicDetailVO();
        contentTopicDetailVO.setTopicId(contentTopicBO.getTopicId());
        contentTopicDetailVO.setTopicType(contentTopicBO.getTopicType() == null ? null : contentTopicBO.getTopicType().getType());
        contentTopicDetailVO.setTopicTypeStr(contentTopicBO.getTopicType() == null ? null : contentTopicBO.getTopicType().getName());
        contentTopicDetailVO.setContentCount(contentTopicBO.getContentCount());
        contentTopicDetailVO.setName(contentTopicBO.getName());
        contentTopicDetailVO.setDesc(contentTopicBO.getDesc());
        contentTopicDetailVO.setBackendImg(contentTopicBO.getBackendImg());
        contentTopicDetailVO.setIsEnable(contentTopicBO.getIsEnable() == null ? null : contentTopicBO.getIsEnable().getType());
        contentTopicDetailVO.setSeeCount(contentTopicBO.getSeeCount());
        contentTopicDetailVO.setJoinCount(contentTopicBO.getJoinCount());
        return contentTopicDetailVO;
    }


    public static PageResult<ContentClassifyBaseVO> convertToPageContentClassifyBaseVO(PageResult<ContentClassifyBO> pageResult) {
        if (pageResult == null) {
            return null;
        }
        if (CollectionUtils.isEmpty(pageResult.getResults())) {
            return PageResult.of(null, pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal());
        }
        return PageResult.of(pageResult.getResults().stream().map(ContentConvert::convertToContentClassifyBaseVO).collect(Collectors.toList()), pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal());
    }

    private static ContentClassifyBaseVO convertToContentClassifyBaseVO(ContentClassifyBO contentClassifyBO) {
        if (contentClassifyBO == null) {
            return null;
        }
        ContentClassifyBaseVO contentClassifyBaseVO = new ContentClassifyBaseVO();
        contentClassifyBaseVO.setClassifyId(contentClassifyBO.getClassifyId());
        contentClassifyBaseVO.setName(contentClassifyBO.getName());
        contentClassifyBaseVO.setCode(contentClassifyBO.getCode());
        contentClassifyBaseVO.setMainImg(contentClassifyBO.getMainImg());
        contentClassifyBaseVO.setIsEnable(contentClassifyBO.getIsEnable() == null ? null : contentClassifyBO.getIsEnable().getType());
        contentClassifyBaseVO.setBusinessScene(contentClassifyBO.getBusinessScene() == null ? null : contentClassifyBO.getBusinessScene().getScene());
        return contentClassifyBaseVO;
    }


    public static ContentClassifyDetailVO convertToContentClassifyDetailVO(ContentClassifyBO contentClassifyBO) {
        if (contentClassifyBO == null) {
            return null;
        }
        ContentClassifyDetailVO contentClassifyDetailVO = new ContentClassifyDetailVO();
        contentClassifyDetailVO.setClassifyId(contentClassifyBO.getClassifyId());
        contentClassifyDetailVO.setName(contentClassifyBO.getName());
        contentClassifyDetailVO.setCode(contentClassifyBO.getCode());
        contentClassifyDetailVO.setDesc(contentClassifyBO.getDesc());
        contentClassifyDetailVO.setMainImg(contentClassifyBO.getMainImg());
        contentClassifyDetailVO.setIsEnable(contentClassifyBO.getIsEnable() == null ? null : contentClassifyBO.getIsEnable().getType());
        contentClassifyDetailVO.setBusinessScene(contentClassifyBO.getBusinessScene() == null ? null : contentClassifyBO.getBusinessScene().getScene());
        return contentClassifyDetailVO;
    }

    public static List<ContentClassifyBaseVO> convertToContentClassifyBaseVOList(List<ContentClassifyBO> responseList) {
        if (CollectionUtils.isEmpty(responseList)) {
            return Lists.newArrayList();
        }
        return responseList.stream().map(ContentConvert::convertToContentClassifyBaseVO).collect(Collectors.toList());
    }

    public static PageResult<ContentBaseVO> buildPageContentBaseVO(PageResult<ContentInfoBO> pageResult, BaseUserInfoResponse userAccountResponse, Boolean currentLoginUser) {
        if (pageResult == null) {
            return null;
        }
        if (CollectionUtils.isEmpty(pageResult.getResults())) {
            return PageResult.of(Lists.newArrayList(), pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal());
        }
        PageResult<ContentBaseVO> result = new PageResult<>();
        result.setPageNum(pageResult.getPageNum());
        result.setPageSize(pageResult.getPageSize());
        result.setTotal(pageResult.getTotal());
        result.setResults(pageResult.getResults().stream().map(item -> buildContentBaseVO(item, userAccountResponse, currentLoginUser)).collect(Collectors.toList()));
        result.setHasNext(pageResult.isHasNext());
        result.setCurrentIndex(pageResult.getCurrentIndex());
        return result;
    }

    private static ContentBaseVO buildContentBaseVO(ContentInfoBO contentBaseInfoResponse, BaseUserInfoResponse userAccountResponse, Boolean currentLoginUser) {
        if (contentBaseInfoResponse == null) {
            return null;
        }
        ContentBaseVO contentBaseVO = new ContentBaseVO();
        contentBaseVO.setTitle(contentBaseInfoResponse.getTitle());
        contentBaseVO.setMainImg(contentBaseInfoResponse.getMainImg());
        contentBaseVO.setContentId(contentBaseInfoResponse.getId());
        contentBaseVO.setAllowComment(contentBaseInfoResponse.getAllowComment() == null ? null : contentBaseInfoResponse.getAllowComment().getType());
        contentBaseVO.setSeeCount(contentBaseInfoResponse.getSeeCount());
        contentBaseVO.setLikeCount(contentBaseInfoResponse.getLikeCount());
        contentBaseVO.setCommentCount(contentBaseInfoResponse.getCommentCount());
        contentBaseVO.setBelongCurrentUser(contentBaseInfoResponse.getUserId() != null && contentBaseInfoResponse.getUserId().equals(userAccountResponse.getUserId()));
        contentBaseVO.setUserVO(convertToBaseUserVO(userAccountResponse));
        contentBaseVO.setSummary(StringUtils.substring(contentBaseInfoResponse.getContent(), 0, 20));
        contentBaseVO.setClassifyName(contentBaseInfoResponse.getClassifyCode());
        contentBaseVO.setBelongCurrentUser(currentLoginUser);
        return contentBaseVO;
    }

    public static BaseUserVO convertToBaseUserVO(BaseUserInfoResponse userAccountResponse) {
        if (userAccountResponse == null) {
            return null;
        }
        BaseUserVO baseUserVO = new BaseUserVO();
        baseUserVO.setUserId(String.valueOf(userAccountResponse.getUserId()));
        baseUserVO.setUserName(userAccountResponse.getUserName());
        baseUserVO.setUserNikeName(userAccountResponse.getNickName());
        baseUserVO.setUserAvatar(userAccountResponse.getHeadImg());
        return baseUserVO;
    }

    public static ContentDetailResponse convertToContentDetailResponse(ContentDetailBO contentDetailBO) {
        if (contentDetailBO == null || contentDetailBO.getContentInfoBO() == null) {
            return null;
        }
        ContentInfoBO contentInfoBO = contentDetailBO.getContentInfoBO();
        ContentDetailResponse contentDetailResponse = new ContentDetailResponse();
        contentDetailResponse.setTitle(contentInfoBO.getTitle());
        contentDetailResponse.setContent(contentInfoBO.getContent());
        contentDetailResponse.setContentId(contentInfoBO.getId());
        contentDetailResponse.setStatus(contentInfoBO.getStatus());
        contentDetailResponse.setMainImg(contentInfoBO.getMainImg());
        contentDetailResponse.setSeeCount(contentInfoBO.getSeeCount());
        contentDetailResponse.setLikeCount(contentInfoBO.getLikeCount());
        contentDetailResponse.setCommentCount(contentInfoBO.getCommentCount());
        contentDetailResponse.setAllowComment(contentInfoBO.getAllowComment());
        contentDetailResponse.setClassifyCode(contentInfoBO.getClassifyCode());
        contentDetailResponse.setUserId(contentInfoBO.getUserId());
        contentDetailResponse.setIsPrivate(contentInfoBO.getIsPrivate());
        if (contentInfoBO.getExtra() != null) {
            contentDetailResponse.setExtra(new ContentDetailResponse.Extra());
            contentDetailResponse.getExtra().setRelationImgList(contentInfoBO.getExtra().getRelationImgList());
        }
        if (CollectionUtils.isNotEmpty(contentDetailBO.getContentRelationBOList())) {
            List<ContentRelation> relationList = new ArrayList<>();
            List<ContentRelationBO> contentRelationBOList = contentDetailBO.getContentRelationBOList();
            for (ContentRelationBO contentRelationBO : contentRelationBOList) {
                ContentRelation relation = new ContentRelation();
                relation.setRelationId(contentRelationBO.getRelationId());
                relation.setJumpUrl(contentRelationBO.getJumpUrl());
                relation.setRelationType(contentRelationBO.getRelationType());
                relation.setSort(contentRelationBO.getSort());
                relation.setIsOutside(contentRelationBO.getIsOutside());
                relationList.add(relation);
            }
            contentDetailResponse.setContentRelationList(relationList);
        }
        return contentDetailResponse;
    }

    public static ContentDetailVO convertToContentDetailVO(ContentDetailBO contentDetailBO, BaseUserInfoResponse userAccountResponse) {
        if (contentDetailBO == null || contentDetailBO.getContentInfoBO() == null) {
            return null;
        }
        ContentInfoBO contentInfoBO = contentDetailBO.getContentInfoBO();
        ContentDetailVO contentDetailVO = new ContentDetailVO();
        contentDetailVO.setUserVO(convertToBaseUserVO(userAccountResponse));
        contentDetailVO.setTitle(contentInfoBO.getTitle());
        contentDetailVO.setContent(contentInfoBO.getContent());
        contentDetailVO.setContentId(contentInfoBO.getId());
        contentDetailVO.setStatus(contentInfoBO.getStatus() == null ? null : contentInfoBO.getStatus().getType());
        contentDetailVO.setStatusStr(contentInfoBO.getStatus() == null ? null : contentInfoBO.getStatus().getName());
        contentDetailVO.setRelationImgList(contentInfoBO.getExtra() == null ? null : contentInfoBO.getExtra().getRelationImgList());
        contentDetailVO.setMainImg(contentInfoBO.getMainImg());
        contentDetailVO.setSeeCount(contentInfoBO.getSeeCount());
        contentDetailVO.setLikeCount(contentInfoBO.getLikeCount());
        contentDetailVO.setCommentCount(contentInfoBO.getCommentCount());
        contentDetailVO.setAllowComment(contentInfoBO.getAllowComment() == null ? null : contentInfoBO.getAllowComment().getType());
        contentDetailVO.setClassifyCode(contentInfoBO.getClassifyCode());
        contentDetailVO.setIsPrivate(contentInfoBO.getIsPrivate() == null ? null : contentInfoBO.getIsPrivate().getType());
        if (CollectionUtils.isNotEmpty(contentDetailBO.getContentRelationBOList())) {
            List<ContentDetailVO.Relation> relationList = new ArrayList<>();
            List<ContentRelationBO> relationList1 = contentDetailBO.getContentRelationBOList();
            for (ContentRelationBO relation : relationList1) {
                ContentDetailVO.Relation relationVO = new ContentDetailVO.Relation();
                relationVO.setRelationId(relation.getRelationId());
                relationVO.setJumpUrl(relation.getJumpUrl());
                relationVO.setRelationType(relation.getRelationType() == null ? null : relation.getRelationType().getType());
                relationVO.setRelationTypeStr(relation.getRelationType() == null ? null : relation.getRelationType().getName());
                relationVO.setRelationImg(relation.getRelationImg());
                relationVO.setRelationName(relation.getRelationName());
                relationVO.setSort(relation.getSort());
                relationVO.setIsOutside(relation.getIsOutside());
                relationList.add(relationVO);
            }
            contentDetailVO.setRelationList(relationList);
        }
        return contentDetailVO;
    }


    public static ContentDetailBO convertToInsertContentParam(InsertContentParam param) {
        if (param == null) {
            return null;
        }
        ContentDetailBO contentDetailBO = new ContentDetailBO();
        ContentInfoBO contentInfoBO = new ContentInfoBO();
        contentInfoBO.setId(TodoCommonUtils.buildLongGuid());
        contentInfoBO.setTitle(param.getTitle());
        contentInfoBO.setContent(param.getContent());
        contentInfoBO.setClassifyCode(param.getClassifyCode());
        contentInfoBO.setAllowComment(AllowedCommentEnum.getByType(param.getAllowComment()));
        contentInfoBO.setIsPrivate(PrivateTypeEnum.getByType(param.getIsPrivate()));
        contentInfoBO.setUserId(param.get_user().getUserId());
        if (CollectionUtils.isNotEmpty(param.getRelationImgList())) {
            contentInfoBO.setExtra(new ContentInfoBO.Extra());
            contentInfoBO.getExtra().setRelationImgList(param.getRelationImgList());
        }
        contentInfoBO.setMainImg(param.getMainImg());
        if (CollectionUtils.isNotEmpty(param.getRelationList())) {
            List<ContentRelationBO> relationList = new ArrayList<>();
            for (InsertContentParam.Relation relation : param.getRelationList()) {
                ContentRelationBO relationRequest = new ContentRelationBO();
                relationRequest.setRelationId(relation.getRelationId());
                relationRequest.setRelationImg(relation.getRelationImg());
                relationRequest.setRelationName(relation.getRelationName());
                relationRequest.setJumpUrl(relation.getJumpUrl());
                relationRequest.setIsOutside(relation.getIsOutside());
                relationRequest.setRelationType(ContentRelationTypeEnum.getByType(relation.getRelationType()));
                relationRequest.setSort(relation.getSort());
                relationList.add(relationRequest);
            }
            contentDetailBO.setContentRelationBOList(relationList);
        }
        contentDetailBO.setContentInfoBO(contentInfoBO);
        return contentDetailBO;
    }

    public static ContentDetailBO convertToContentDetailBO(UpdateContentParam param) {
        if (param == null || param.getContentId() == null) {
            return null;
        }
        ContentDetailBO contentDetailBO = new ContentDetailBO();
        ContentInfoBO contentInfoBO = new ContentInfoBO();
        contentInfoBO.setId(Long.valueOf(param.getContentId()));
        contentInfoBO.setUserId(param.get_user().getUserId());
        contentInfoBO.setTitle(param.getTitle());
        contentInfoBO.setContent(param.getContent());
        contentInfoBO.setClassifyCode(param.getClassifyCode());
        contentInfoBO.setAllowComment(AllowedCommentEnum.getByType(param.getAllowComment()));
        contentInfoBO.setIsPrivate(PrivateTypeEnum.getByType(param.getIsPrivate()));
        if (CollectionUtils.isNotEmpty(param.getRelationImgList())) {
            contentInfoBO.setExtra(new ContentInfoBO.Extra());
            contentInfoBO.getExtra().setRelationImgList(param.getRelationImgList());
        }
        contentInfoBO.setMainImg(param.getMainImg());
        if (CollectionUtils.isNotEmpty(param.getRelationList())) {
            List<ContentRelationBO> relationList = new ArrayList<>();
            for (UpdateContentParam.Relation relation : param.getRelationList()) {
                ContentRelationBO relationRequest = new ContentRelationBO();
                relationRequest.setRelationId(relation.getRelationId());
                relationRequest.setRelationImg(relation.getRelationImg());
                relationRequest.setRelationName(relation.getRelationName());
                relationRequest.setJumpUrl(relation.getJumpUrl());
                relationRequest.setIsOutside(relation.getIsOutside());
                relationRequest.setRelationType(ContentRelationTypeEnum.getByType(relation.getRelationType()));
                relationRequest.setSort(relation.getSort());
                relationList.add(relationRequest);
            }
            contentDetailBO.setContentRelationBOList(relationList);
        }
        contentDetailBO.setContentInfoBO(contentInfoBO);
        return contentDetailBO;
    }

    public static ContentDetailEntity buildInsertContentDetailEntity(ContentDetailBO contentDetailBO) {
        if (contentDetailBO == null || contentDetailBO.getContentInfoBO() == null) {
            return null;
        }
        ContentInfoBO contentInfoBO = contentDetailBO.getContentInfoBO();
        ContentDetailEntity contentDetailEntity = new ContentDetailEntity();
        contentDetailEntity.setMysqlId(contentInfoBO.getId());
        contentDetailEntity.setUserId(contentInfoBO.getUserId());
        contentDetailEntity.setContent(contentInfoBO.getContent());
        contentDetailEntity.setClassifyCode(contentInfoBO.getClassifyCode());
        contentDetailEntity.setTitle(contentInfoBO.getTitle());
        contentDetailEntity.setStatus(contentInfoBO.getStatus() == null ? null : contentInfoBO.getStatus().getType());
        contentDetailEntity.setIsPrivate(contentInfoBO.getIsPrivate() == null ? null : contentInfoBO.getIsPrivate().getType());
        contentDetailEntity.setAllowComment(contentInfoBO.getAllowComment() == null ? null : contentInfoBO.getAllowComment().getType());
        contentDetailEntity.setMainImg(contentInfoBO.getMainImg());
        contentDetailEntity.setSeeCount(contentInfoBO.getSeeCount());
        contentDetailEntity.setLikeCount(contentInfoBO.getLikeCount());
        contentDetailEntity.setCommentCount(contentInfoBO.getCommentCount());
        contentDetailEntity.setCollectCount(contentInfoBO.getCollectCount());
        return contentDetailEntity;
    }
}
